Refactor: extract OCR/QR result post-processing into TextRecognition#12
Merged
Merged
Conversation
The OCR line-join + empty/line-count logic was duplicated across CaptureManager.runOCR and EditorView.performOCR, and the QR payload->openable-URL decision lived inline in performQRScan. Lift the pure post-processing out of the Vision closures into TextRecognition.ocrOutcome(from:) / barcodeOutcome(from:), which classify already-extracted strings. The Vision request setup and the toast/alert presentation stay at the call sites. Behavior-preserving: same join separator, same line counting (joined components), clipboard text is still all payloads joined, the alert still shows the first raw payload and opens the first URL. Adds TextRecognitionTests (10 cases).
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
…12) Lift the pure OCR/QR post-processing out of the Vision closures in CaptureManager.runOCR and EditorView.performOCR/performQRScan into TextRecognition.ocrOutcome(from:) / barcodeOutcome(from:), removing the OCR line-join/count duplication. Vision setup and toast/alert presentation stay at the call sites. Behavior-preserving. Adds TextRecognitionTests (10 cases). CI green.
GamalAnwar
added a commit
that referenced
this pull request
Jun 18, 2026
…12) Lift the pure OCR/QR post-processing out of the Vision closures in CaptureManager.runOCR and EditorView.performOCR/performQRScan into TextRecognition.ocrOutcome(from:) / barcodeOutcome(from:), removing the OCR line-join/count duplication. Vision setup and toast/alert presentation stay at the call sites. Behavior-preserving. Adds TextRecognitionTests (10 cases). CI green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Target 1 of the remaining heavier slices (OCR/QR path). The pure post-processing of Vision results was buried inside the recognition closures and duplicated:
CaptureManager.runOCRandEditorView.performOCR.EditorView.performQRScan.This lifts the testable logic out into a
TextRecognitionmodule that classifies already-extracted strings (so tests need no Vision objects):The Vision request setup (
VNRecognizeTextRequest/VNDetectBarcodesRequest, recognition level, symbologies) and the toast/alert presentation stay at the call sites — those are AppKit/Vision-coupled and not worth mocking. The three closures now just switch on the outcome.Scope / safety
\njoin separator; line count is the joined string's component count (matches the oldCaptureManagerbehavior, and equalstexts.countin practice since each observation is one line).firstPayload, not the normalized URL) and opens the first payload's URL.if let errorguards in both editor closures are untouched.Tests
TextRecognitionTests(10 cases): OCR empty/whitespace →.noText, single + multi-line join/count; barcode none, URL payload surfaces URL, non-URL → nil URL,mailto:scheme openable, multi-payload joins text while keeping the first for the URL check, and non-URL-first stays nil.🤖 Generated with Claude Code
Generated by Claude Code